<?php
declare (strict_types=1);

namespace app\admin\controller;

use addons\Builder\facade\Builder;
use app\common\model\Assets;
use think\App;
use think\response\Json;

class Draw extends Base
{
    //主键，默认为id
    protected string $pk = 'id';

    //主模型
    protected string $model = '\app\common\model\Draw';

    //关联模型
    protected array $hasOne = ['user'];

    public function index(): string
    {
        return Builder::Table()
            ->autoStructure($this->model, $this->pk, 'barDemo,100')
            ->addRightButtons(['edit' => ['title' => '查看', 'unity_title' => '审核/查看', 'size' => '60%']])
            ->addTopButtons([
                'batchAudit' => [
                    'title' => '批量审核', 'icon' => 'layui-icon-util',
                    'url'   => url('draw/batch')->build(),
                    'event' => '_batchSubmit'
                ],
                'export'])
            ->addSearch([
                ['uid', '会员编号/昵称/手机号', 'input', '', '\app\common\model\User', 'code|nickname|mobile,id'],
                ['account', '账户类型', 'select', Assets::getFields(3)]
            ])
            ->fetch();
    }

    public function edit($id = '', $tpl = 'draw/edit', $info = ''): string
    {
        return parent::edit($id, $tpl, $info); // TODO: Change the autogenerated stub
    }

    public function save($param = [], $model = true): Json
    {
        return parent::save($param, $model); // TODO: Change the autogenerated stub
    }

    public function batch()
    {
        return $this->model::batch($this->request->param('ids'), $this->admin);
    }
}
